package com.easyj.base.common.page;

import java.io.Serializable;

public class PageFilter  implements Serializable{

	private static final long serialVersionUID = 1616218001870405457L;
	private Integer limit; //pageSize
	private Long offset;
	
	//private Integer pageNumber;//计算出来
	
	public PageFilter(){
		
	}
	
	public PageFilter( Integer limit,int pageNo){
		this.limit=limit;
		this.offset=(long)(pageNo-1)*limit;
	}
	
	public PageFilter( Integer limit,Long offset){
		this.limit=limit;
		this.offset=offset;
	}
	
	
	public void setLimit(Integer limit) {
		this.limit = limit;
	}

	public void setOffset(Long offset) {
		this.offset = offset;
	}
	

	public Integer getLimit() {
		return limit;
	}
	public Long getOffset() {
		return offset;
	}
	
	//--------------
	public Integer getPageNumber() {
		int number=1;
		if(offset!=null && limit!=null){
			number=(offset.intValue()/limit)+1;
			
		}
		return number;
	}

	public Integer getPageSize() {
		return limit;
	}
	
	/**
	 * 根据查询返回的总数
	 * 重新处理offset （由于删除数据，所以前端设置的offset,可能大于数据总量的，所以要重设回最后一页）
	 * @param total
	 */
	public void resetOffsetByTotal(Long total){
		if(getOffset()>0&&total<=getOffset()){
			long totalPage = total/limit;
			if(total%limit>0){
				totalPage=totalPage+1;
			}
			setOffset((totalPage-1)*limit);
		}
	}
	
	
}
